package com.ms.monitor.init;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.system.comm.utils.FrameStringUtil;
import com.system.dao.BaseDao;
import com.system.dao.utils.DbUtil;
import com.system.ds.DbContextHolder;

/**
 * 脚本升级
 * @author yuejing
 * @date 2018年12月18日 上午11:17:25
 */
public class DbUpdate {

	private static final Logger LOGGER = LoggerFactory.getLogger(DbUpdate.class);

	/**
	 * 初始化更新后的脚本
	 */
	public static void init() {
		updateSql();
	}
	private static void updateSql() {
		DbContextHolder.setDsName("dataSource1");
		BaseDao baseDao = new BaseDao();
		if (DbUtil.isMysql()) {
			version1_0_0(baseDao);
		} else if (DbUtil.isOracle()) {
			// TODO 带扩展Oracle的初始化脚本
		}

	}

	private static void version1_0_0(BaseDao baseDao) {
		createCliInfo(baseDao);
		createCodeCreate(baseDao);
		createCodePrj(baseDao);
		createCodeTemplate(baseDao);
		createMsConfig(baseDao);
		createMsSecret(baseDao);
		createMsSecretApi(baseDao);
		createPrjApi(baseDao);
		createPrjClient(baseDao);
		createPrjDs(baseDao);
		createPrjInfo(baseDao);
		createPrjMonitor(baseDao);
		createPrjOptimize(baseDao);
		createPrjOptimizeLog(baseDao);
		createPrjVersion(baseDao);
		createPrjVersionScript(baseDao);
		createSysConfig(baseDao);
		createSysFile(baseDao);
		createSysUser(baseDao);
		createSysUserAtt(baseDao);
		createSysRole(baseDao);
		createMsUser(baseDao);
		createMsGray(baseDao);
		createMsGrayUser(baseDao);

		createBizLog(baseDao);
		createBizLogDtl(baseDao);
		
		createAppInfo(baseDao);
		createAppPrj(baseDao);
		createAppUser(baseDao);
		createAppApiTest(baseDao);
		createAppApiTestDtl(baseDao);
		createAppApiTestLog(baseDao);
		createAppAnt(baseDao);
	}

	private static void createAppAnt(BaseDao baseDao) {
		try {
			baseDao.queryForLong("select count(*) from app_ant limit 1");
		} catch (Exception e) {
			LOGGER.info("|===================================================");
			LOGGER.error("|========== 不存在表[app_ant]: " + e.getMessage());
			String sql = "create table app_ant\r\n" + 
					"(\r\n" + 
					"   aa_id                varchar(32) not null comment '编号',\r\n" + 
					"   ai_id                varchar(32) not null comment '应用编号',\r\n" + 
					"   type                 int comment '类型[10url/20截图]',\r\n" + 
					"   type_value           varchar(1024) null comment '类型值',\r\n" + 
					"   name                 varchar(512) not null comment '名称',\r\n" + 
					"   remark               varchar(1024) comment '备注',\r\n" + 
					"   api_info             text comment 'api信息',\r\n" + 
					"   parent_aa_id         varchar(32) not null comment '父编号',\r\n" + 
					"   create_user_id       int not null comment '创建人',\r\n" + 
					"   create_time          datetime not null comment '创建时间',\r\n" + 
					"   primary key (aa_id)\r\n" + 
					");\r\n" + 
					"\r\n" + 
					"alter table app_ant comment '应用原型表';";
			batchExec(sql, baseDao);
			LOGGER.info("|===================================================");
		}
	}
	private static void createAppApiTestLog(BaseDao baseDao) {
		try {
			baseDao.queryForLong("select count(*) from app_api_test_log limit 1");
		} catch (Exception e) {
			LOGGER.info("|===================================================");
			LOGGER.error("|========== 不存在表[app_api_test_log]: " + e.getMessage());
			String sql = "create table app_api_test_log\r\n" + 
					"(\r\n" + 
					"   aatl_id              varchar(32) not null comment '编码',\r\n" + 
					"   batch_no             varchar(32) not null comment '批次[测试时间]',\r\n" + 
					"   aatd_id              varchar(32) not null comment '测试接口编号',\r\n" + 
					"   test_user_id         int not null comment '测试人',\r\n" + 
					"   test_time            datetime not null comment '测试时间',\r\n" + 
					"   params               text comment '入参',\r\n" + 
					"   result               text comment '响应结果',\r\n" + 
					"   result_succ          text comment '正确结果',\r\n" + 
					"   status               int comment '状态[30成功、40失败]',\r\n" + 
					"   status_msg           varchar(512) comment '状态消息',\r\n" + 
					"   result_comparison    text comment '对比结果',\r\n" + 
					"   primary key (aatl_id)\r\n" + 
					");\r\n" + 
					"\r\n" + 
					"alter table app_api_test_log comment '应用API测试记录表';";
			batchExec(sql, baseDao);
			LOGGER.info("|===================================================");
		}
	}
	private static void createAppApiTestDtl(BaseDao baseDao) {
		try {
			baseDao.queryForLong("select count(*) from app_api_test_dtl limit 1");
		} catch (Exception e) {
			LOGGER.info("|===================================================");
			LOGGER.error("|========== 不存在表[app_api_test_dtl]: " + e.getMessage());
			String sql = "create table app_api_test_dtl\r\n" + 
					"(\r\n" + 
					"   aatd_id              varchar(32) not null comment '项目API测试编号',\r\n" + 
					"   aat_id               varchar(32) not null comment '应用API测试编号',\r\n" + 
					"   prj_id               int not null comment '项目编号',\r\n" + 
					"   path                 varchar(150) not null comment '项目API路径',\r\n" + 
					"   orderby              float not null comment '排序号',\r\n" + 
					"   params               text not null comment '参数',\r\n" + 
					"   status               int not null comment '状态[10待测试、20测试中、30成功、40失败]',\r\n" + 
					"   succ_result          text not null comment '成功结果',\r\n" + 
					"   create_user_id       int not null comment '创建人',\r\n" + 
					"   create_time          datetime not null comment '创建时间',\r\n" + 
					"   aatl_id              varchar(32) comment '测试记录编号',\r\n" + 
					"   primary key (aatd_id)\r\n" + 
					");\r\n" + 
					"\r\n" + 
					"alter table app_api_test_dtl comment '应用API测试接口表';";
			batchExec(sql, baseDao);
			LOGGER.info("|===================================================");
		}
	}
	private static void createAppApiTest(BaseDao baseDao) {
		try {
			baseDao.queryForLong("select count(*) from app_api_test limit 1");
		} catch (Exception e) {
			LOGGER.info("|===================================================");
			LOGGER.error("|========== 不存在表[app_api_test]: " + e.getMessage());
			String sql = "create table app_api_test\r\n" + 
					"(\r\n" + 
					"   aat_id               varchar(32) not null comment '编号',\r\n" + 
					"   ai_id                varchar(32) not null comment '应用编号',\r\n" + 
					"   name                 varchar(512) not null comment '测试名称',\r\n" + 
					"   remark               varchar(512) comment '备注',\r\n" + 
					"   create_user_id       int not null comment '创建人',\r\n" + 
					"   create_time          datetime not null comment '创建时间',\r\n" + 
					"   test_time            datetime comment '测试时间',\r\n" + 
					"   test_result          varchar(255) comment '测试结果',\r\n" + 
					"   primary key (aat_id)\r\n" + 
					");\r\n" + 
					"\r\n" + 
					"alter table app_api_test comment '应用API测试表';";
			batchExec(sql, baseDao);
			LOGGER.info("|===================================================");
		}
	}
	private static void createAppUser(BaseDao baseDao) {
		String sql = null;
		try {
			baseDao.queryForLong("select count(*) from app_user limit 1");
		} catch (Exception e) {
			LOGGER.info("|===================================================");
			LOGGER.error("|========== 不存在表[app_user]: " + e.getMessage());
			sql = "create table app_user\n" + 
					"(\n" + 
					"   ai_id                varchar(32) not null comment '应用编号',\n" + 
					"   user_id              int not null comment '用户编号',\n" + 
					"   create_user_id       int not null comment '创建人',\n" + 
					"   create_time          datetime not null comment '创建时间',\n" + 
					"   primary key (ai_id, user_id)\n" + 
					");\n" + 
					"\n" + 
					"alter table app_user comment '应用成员表';";
			batchExec(sql, baseDao);
			LOGGER.info("|===================================================");
		}
	}
	private static void createAppPrj(BaseDao baseDao) {
		String sql = null;
		try {
			baseDao.queryForLong("select count(*) from app_prj limit 1");
		} catch (Exception e) {
			LOGGER.info("|===================================================");
			LOGGER.error("|========== 不存在表[app_prj]: " + e.getMessage());
			sql = "create table app_prj\n" + 
					"(\n" + 
					"   ai_id                varchar(32) not null comment '应用编号',\n" + 
					"   prj_id               int(11) not null comment '项目编号',\n" + 
					"   create_user_id       int(11) not null comment '创建人',\n" + 
					"   create_time          datetime not null comment '创建时间',\n" + 
					"   primary key (ai_id, prj_id)\n" + 
					");\n" + 
					"\n" + 
					"alter table app_prj comment '应用项目表';";
			batchExec(sql, baseDao);
			LOGGER.info("|===================================================");
		}
	}
	private static void createAppInfo(BaseDao baseDao) {
		String sql = null;
		try {
			baseDao.queryForLong("select count(*) from app_info limit 1");
		} catch (Exception e) {
			LOGGER.info("|===================================================");
			LOGGER.error("|========== 不存在表[app_info]: " + e.getMessage());
			sql = "create table app_info\n" + 
					"(\n" + 
					"   ai_id                varchar(32) not null comment '编号',\n" + 
					"   code                 varchar(32) not null comment '编码',\n" + 
					"   name                 varchar(512) not null comment '名称',\n" + 
					"   remark               text comment '备注',\n" + 
					"   create_user_id       int(11) not null comment '创建人',\n" + 
					"   create_time          datetime not null comment '创建时间',\n" + 
					"   primary key (ai_id)\n" + 
					");\n" + 
					"\n" + 
					"alter table app_info comment '应用表';";
			batchExec(sql, baseDao);
			LOGGER.info("|===================================================");
		}
	}
	private static void createSysRole(BaseDao baseDao) {
		String sql = null;
		try {
			baseDao.queryForLong("select count(*) from sys_role limit 1");
		} catch (Exception e) {
			LOGGER.info("|===================================================");
			LOGGER.error("|========== 不存在表[sys_role]: " + e.getMessage());
			sql = "CREATE TABLE `sys_role` (\r\n" + 
					"  `role_id` int(11) NOT NULL auto_increment COMMENT '编号',\r\n" + 
					"  `name` varchar(256) NOT NULL COMMENT '名称',\r\n" + 
					"  `create_user_id` int(11) NOT NULL COMMENT '创建人',\r\n" + 
					"  `create_time` datetime NOT NULL COMMENT '创建时间',\r\n" + 
					"  `auth_ids` text COMMENT '权限编码',\r\n" + 
					"  PRIMARY KEY  (`role_id`)\r\n" + 
					") ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='角色';";
			sql += "insert into `sys_role` (`role_id`, `name`, `create_user_id`, `create_time`, `auth_ids`) values('1','管理员','1','2020-11-12 15:42:59','workbench,app,appInfoManager,prj,prjInfoManager,sys,sysUserManager,sysRoleManager,sysConfigManager');";
			batchExec(sql, baseDao);
			LOGGER.info("|===================================================");
		}
	}
	private static void createBizLog(BaseDao baseDao) {
		try {
			baseDao.queryForLong("select count(*) from biz_log limit 1");
		} catch (Exception e) {
			LOGGER.info("|===================================================");
			LOGGER.error("|========== 不存在表[biz_log]: " + e.getMessage());
			String sql = "CREATE TABLE `biz_log` (\r\n" + 
					"  `trace_id` varchar(32) NOT NULL COMMENT '唯一标识',\r\n" + 
					"  `req_param1` varchar(100) default NULL COMMENT '请求标记1',\r\n" + 
					"  `req_param2` varchar(100) default NULL COMMENT '请求标记2',\r\n" + 
					"  `req_param3` varchar(100) default NULL COMMENT '请求标记3',\r\n" + 
					"  `req_time` datetime NOT NULL COMMENT '请求时间',\r\n" + 
					"  PRIMARY KEY  (`trace_id`)\r\n" + 
					") ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='业务日志表';";
			batchExec(sql, baseDao);
			LOGGER.info("|===================================================");
		}
	}private static void createBizLogDtl(BaseDao baseDao) {
		try {
			baseDao.queryForLong("select count(*) from biz_log_dtl limit 1");
		} catch (Exception e) {
			LOGGER.info("|===================================================");
			LOGGER.error("|========== 不存在表[biz_log_dtl]: " + e.getMessage());
			String sql = "CREATE TABLE `biz_log_dtl` (\r\n" + 
					"  `bld_id` varchar(32) NOT NULL COMMENT '编号',\r\n" + 
					"  `span_id` varchar(32) NOT NULL COMMENT '单个日志编码',\r\n" + 
					"  `trace_id` varchar(32) NOT NULL COMMENT '唯一标识',\r\n" + 
					"  `req_time` bigint(20) NOT NULL COMMENT '请求时间戳',\r\n" + 
					"  `req_key` varchar(250) NOT NULL COMMENT '请求key',\r\n" + 
					"  `req_value` longtext COMMENT '请求value',\r\n" + 
					"  `ext1` varchar(250) default NULL COMMENT '扩展1',\r\n" + 
					"  `ext2` varchar(250) default NULL COMMENT '扩展2',\r\n" + 
					"  `ext3` varchar(250) default NULL COMMENT '扩展3',\r\n" + 
					"  PRIMARY KEY  (`bld_id`)\r\n" + 
					") ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='业务日志记录表';";
			batchExec(sql, baseDao);
			LOGGER.info("|===================================================");
		}
	}
	private static void createMsGray(BaseDao baseDao) {
		try {
			baseDao.queryForLong("select count(*) from ms_gray limit 1");
		} catch (Exception e) {
			LOGGER.info("|===================================================");
			LOGGER.error("|========== 不存在表[ms_gray]: " + e.getMessage());
			String sql = "CREATE TABLE `ms_gray` (\r\n" + 
					"  `mg_id` varchar(32) NOT NULL COMMENT '编号',\r\n" + 
					"  `normal_service_id` varchar(50) NOT NULL COMMENT '正常服务ID',\r\n" + 
					"  `gray_service_id` varchar(50) NOT NULL COMMENT '灰度服务ID',\r\n" + 
					"  `is_use` int(11) NOT NULL COMMENT '是否使用',\r\n" + 
					"  `create_time` datetime NOT NULL COMMENT '创建时间',\r\n" + 
					"  PRIMARY KEY  (`mg_id`)\r\n" + 
					") ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='灰度服务表';";
			batchExec(sql, baseDao);
			LOGGER.info("|===================================================");
		}
	}
	private static void createMsGrayUser(BaseDao baseDao) {
		try {
			baseDao.queryForLong("select count(*) from ms_gray_user limit 1");
		} catch (Exception e) {
			LOGGER.info("|===================================================");
			LOGGER.error("|========== 不存在表[ms_gray_user]: " + e.getMessage());
			String sql = "CREATE TABLE `ms_gray_user` (\r\n" + 
					"  `mg_id` varchar(32) NOT NULL COMMENT '灰度服务编号',\r\n" + 
					"  `type` varchar(30) NOT NULL COMMENT '类型[10具体用户、20其它]',\r\n" + 
					"  `type_value` varchar(150) NOT NULL COMMENT '类型值',\r\n" + 
					"  PRIMARY KEY  (`mg_id`,`type`,`type_value`)\r\n" + 
					") ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='灰度服务用户表';";
			batchExec(sql, baseDao);
			LOGGER.info("|===================================================");
		}
	}
	private static void createMsUser(BaseDao baseDao) {
		try {
			baseDao.queryForLong("select count(*) from ms_user limit 1");
		} catch (Exception e) {
			LOGGER.info("|===================================================");
			LOGGER.error("|========== 不存在表[ms_user]: " + e.getMessage());
			String sql = "CREATE TABLE `ms_user` (\r\n" + 
					"  `mu_id` varchar(32) NOT NULL COMMENT '编号',\r\n" + 
					"  `name` varchar(100) NOT NULL COMMENT '名称',\r\n" + 
					"  `phone` varchar(50) default NULL COMMENT '手机号',\r\n" + 
					"  `remark` varchar(250) NOT NULL COMMENT '备注',\r\n" + 
					"  `create_time` datetime NOT NULL COMMENT '创建时间',\r\n" + 
					"  PRIMARY KEY  (`mu_id`)\r\n" + 
					") ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='微服务用户表';";
			batchExec(sql, baseDao);
			LOGGER.info("|===================================================");
		}
	}
	private static void createSysUserAtt(BaseDao baseDao) {
		try {
			baseDao.queryForLong("select count(*) from sys_user_att limit 1");
		} catch (Exception e) {
			LOGGER.info("|===================================================");
			LOGGER.error("|========== 不存在表[sys_user_att]: " + e.getMessage());
			String sql = "CREATE TABLE `sys_user_att` (\r\n" + 
					"  `user_id` int(11) NOT NULL COMMENT '用户编号',\r\n" + 
					"  `type` varchar(20) NOT NULL COMMENT '类型[10项目]',\r\n" + 
					"  `type_no` varchar(32) NOT NULL COMMENT '类型编码',\r\n" + 
					"  `create_time` datetime NOT NULL COMMENT '创建时间',\r\n" + 
					"  PRIMARY KEY  (`user_id`,`type`,`type_no`)\r\n" + 
					") ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='我的关注表';";
			batchExec(sql, baseDao);
			LOGGER.info("|===================================================");
		}
	}
	private static void createSysUser(BaseDao baseDao) {
		try {
			baseDao.queryForLong("select count(*) from sys_user limit 1");
		} catch (Exception e) {
			LOGGER.info("|===================================================");
			LOGGER.error("|========== 不存在表[sys_user]: " + e.getMessage());
			String sql = "CREATE TABLE `sys_user` (\r\n" + 
					"  `user_id` int(11) NOT NULL auto_increment COMMENT '编号',\r\n" + 
					"  `username` varchar(30) NOT NULL COMMENT '用户名',\r\n" + 
					"  `password` varchar(80) NOT NULL COMMENT '密码',\r\n" + 
					"  `nickname` varchar(30) NOT NULL COMMENT '昵称',\r\n" + 
					"  `create_time` datetime NOT NULL COMMENT '添加时间',\r\n" + 
					"  `status` int(11) NOT NULL COMMENT '状态[10正常、20冻结]',\r\n" + 
					"  `role_id` int(11) default '1' COMMENT '角色编号',\r\n" + 
					"  PRIMARY KEY  (`user_id`),\r\n" + 
					"  UNIQUE KEY `unique_username` (`username`)\r\n" + 
					") ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用户表';";
			sql += "insert  into `sys_user`(`user_id`,`username`,`password`,`nickname`,`create_time`,`status`) values (1,'admin','43286a86708820e38c333cdd4c496355','admin','2016-10-19 10:53:38',10);";
			batchExec(sql, baseDao);
		}
	}
	private static void createSysFile(BaseDao baseDao) {
		try {
			baseDao.queryForLong("select count(*) from sys_file limit 1");
		} catch (Exception e) {
			LOGGER.info("|===================================================");
			LOGGER.error("|========== 不存在表[sys_file]: " + e.getMessage());
			String sql = "CREATE TABLE `sys_file` (\r\n" + 
					"  `file_id` varchar(32) NOT NULL COMMENT '编号',\r\n" + 
					"  `type` int(11) NOT NULL COMMENT '类型[10项目]',\r\n" + 
					"  `org_name` varchar(80) NOT NULL COMMENT '原名称',\r\n" + 
					"  `sys_name` varchar(80) NOT NULL COMMENT '系统名称',\r\n" + 
					"  `url` varchar(200) NOT NULL COMMENT '显示路径',\r\n" + 
					"  `file_type` varchar(20) NOT NULL COMMENT '文件类型',\r\n" + 
					"  `file_size` float NOT NULL COMMENT '文件大小',\r\n" + 
					"  `status` int(11) NOT NULL COMMENT '状态[0待确定、1使用中、2未使用、3已作废]',\r\n" + 
					"  `create_time` datetime NOT NULL COMMENT '添加时间',\r\n" + 
					"  PRIMARY KEY  (`file_id`)\r\n" + 
					") ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='系统文件表';";
			batchExec(sql, baseDao);
			LOGGER.info("|===================================================");
		}
	}
	private static void createSysConfig(BaseDao baseDao) {
		try {
			baseDao.queryForLong("select count(*) from sys_config limit 1");
		} catch (Exception e) {
			LOGGER.info("|===================================================");
			LOGGER.error("|========== 不存在表[sys_config]: " + e.getMessage());
			String sql = "CREATE TABLE `sys_config` (\r\n" + 
					"  `code` varchar(50) NOT NULL COMMENT '编码',\r\n" + 
					"  `name` varchar(50) NOT NULL COMMENT '名称',\r\n" + 
					"  `value` varchar(100) NOT NULL COMMENT '值',\r\n" + 
					"  `remark` varchar(100) default NULL COMMENT '描叙',\r\n" + 
					"  `exp1` varchar(100) default NULL COMMENT '扩展1',\r\n" + 
					"  `exp2` varchar(100) default NULL COMMENT '扩展2',\r\n" + 
					"  PRIMARY KEY  (`code`)\r\n" + 
					") ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='系统参数表';";
			sql += "insert  into `sys_config`(`code`,`name`,`value`,`remark`,`exp1`,`exp2`) values \r\n" + 
					"('mail.from','发送邮件的邮箱','xxx@163.com',NULL,NULL,NULL),\r\n" + 
					"('mail.password','发送邮件的密码','xxxxxx',NULL,NULL,NULL),\r\n" + 
					"('mail.send.is.open','是否打开发送邮件的功能[0否、1是]','0',NULL,NULL,NULL),\r\n" + 
					"('mail.smtp','发送邮箱的smtp','smtp.163.com',NULL,NULL,NULL),\r\n" + 
					"('mail.username','发送邮件的用户名','xxxx',NULL,NULL,NULL),\r\n" + 
					"('prj.file.path','项目上传的目录','D:\\\\data',NULL,NULL,NULL),\r\n" + 
					"('prj.monitor.fail.email','项目检测失败接收的邮箱','yuejing@163.com',NULL,NULL,NULL),\r\n" + 
					"('task.clean.cron','定时任务-清空调度记录表达式','0 0 23 * * ?','',NULL,NULL),\r\n" + 
					"('task.joblog.save.day','定时任务-调度记录保存天数','30','',NULL,NULL),\r\n" + 
					"('task.leader.cron','定时任务-Leader的时间表达式','0/5 * * * * ?','',NULL,NULL),\r\n" + 
					"('task.lock.destroy.time','定时任务-消耗服务和任务的时间[单位:s]','15','',NULL,NULL),\r\n" + 
					"('task.mail.from','定时任务-发送邮件的邮箱','xxx@163.com','',NULL,NULL),\r\n" + 
					"('task.mail.password','定时任务-发送邮件的密码','xxxxxx','',NULL,NULL),\r\n" + 
					"('task.mail.smtp','定时任务-发送邮箱的smtp','smtp.163.com','',NULL,NULL),\r\n" + 
					"('task.mail.username','定时任务-发送邮件的用户名','xxx','',NULL,NULL),\r\n" + 
					"('task.serv.save.day','定时任务-已停止的服务保存天数','30','',NULL,NULL),\r\n" + 
					"('task.task.main.cron','定时任务-主线程的时间表达式','0/8 * * * * ?','',NULL,NULL);";
			batchExec(sql, baseDao);
			LOGGER.info("|===================================================");
		}
	}
	private static void createPrjVersionScript(BaseDao baseDao) {
		try {
			baseDao.queryForLong("select count(*) from prj_version_script limit 1");
		} catch (Exception e) {
			LOGGER.info("|===================================================");
			LOGGER.error("|========== 不存在表[prj_version_script]: " + e.getMessage());
			String sql = "CREATE TABLE `prj_version_script` (\r\n" + 
					"  `pvs_id` int(11) NOT NULL auto_increment COMMENT '编号',\r\n" + 
					"  `prj_id` int(11) NOT NULL COMMENT '项目编号',\r\n" + 
					"  `version` varchar(32) NOT NULL COMMENT '版本号',\r\n" + 
					"  `remark` varchar(100) default NULL COMMENT '备注',\r\n" + 
					"  `ds_code` varchar(32) NOT NULL COMMENT '数据源编号',\r\n" + 
					"  `up_sql` text NOT NULL COMMENT '升级脚本',\r\n" + 
					"  `callback_sql` text COMMENT '回滚脚本',\r\n" + 
					"  `is_up` int(11) NOT NULL COMMENT '是否升级',\r\n" + 
					"  `create_time` datetime NOT NULL COMMENT '添加时间',\r\n" + 
					"  `user_id` int(11) NOT NULL COMMENT '添加人',\r\n" + 
					"  PRIMARY KEY  (`pvs_id`)\r\n" + 
					") ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='项目版本脚本表';";
			batchExec(sql, baseDao);
			LOGGER.info("|===================================================");
		}
	}
	private static void createPrjVersion(BaseDao baseDao) {
		try {
			baseDao.queryForLong("select count(*) from prj_version limit 1");
		} catch (Exception e) {
			LOGGER.info("|===================================================");
			LOGGER.error("|========== 不存在表[prj_version]: " + e.getMessage());
			String sql = "CREATE TABLE `prj_version` (\r\n" + 
					"  `prj_id` int(11) NOT NULL COMMENT '项目编号',\r\n" + 
					"  `version` varchar(50) NOT NULL COMMENT '版本号',\r\n" + 
					"  `remark` varchar(300) default NULL COMMENT '描叙',\r\n" + 
					"  `create_time` datetime NOT NULL COMMENT '添加时间',\r\n" + 
					"  `user_id` int(11) NOT NULL COMMENT '添加人',\r\n" + 
					"  `is_release` int(11) NOT NULL COMMENT '是否发布',\r\n" + 
					"  `path_url` varchar(200) NOT NULL COMMENT '版本所在的路径',\r\n" + 
					"  `rb_version` varchar(50) default NULL COMMENT '回滚版本',\r\n" + 
					"  `is_rel_time` int(11) NOT NULL COMMENT '是否定时发布',\r\n" + 
					"  `rel_time` datetime NOT NULL COMMENT '定时发布时间',\r\n" + 
					"  `rel_status` int(11) NOT NULL COMMENT '定时发布状态[10待发布、20发布中，30发布失败、40发布成功]',\r\n" + 
					"  `rel_msg` varchar(250) default NULL COMMENT '定时发布结果',\r\n" + 
					"  `deploy_type` int(11) default '10' NOT NULL COMMENT '部署类型[10发布包、20GIT部署]',\r\n" + 
					"  `git_info` text default NULL COMMENT 'git部署信息',\r\n" + 
					"  `maven_info` text default NULL COMMENT 'Maven的信息',\r\n" + 
					"  `is_first_deploy` int(11) default '0' COMMENT '是否首次部署',\r\n" + 
					"  PRIMARY KEY  (`prj_id`,`version`)\r\n" + 
					") ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='项目版本表';";
			batchExec(sql, baseDao);
			LOGGER.info("|===================================================");
		}
	}
	private static void createPrjOptimizeLog(BaseDao baseDao) {
		try {
			baseDao.queryForLong("select count(*) from prj_optimize_log limit 1");
		} catch (Exception e) {
			LOGGER.info("|===================================================");
			LOGGER.error("|========== 不存在表[prj_optimize_log]: " + e.getMessage());
			String sql = "CREATE TABLE `prj_optimize_log` (\r\n" + 
					"  `id` int(11) NOT NULL auto_increment COMMENT '编号',\r\n" + 
					"  `prj_id` int(11) NOT NULL COMMENT '项目编号',\r\n" + 
					"  `url` varchar(200) NOT NULL COMMENT '接口地址',\r\n" + 
					"  `params` text COMMENT '请求参数',\r\n" + 
					"  `req_time` datetime NOT NULL COMMENT '请求时间',\r\n" + 
					"  `res_time` datetime NOT NULL COMMENT '响应时间',\r\n" + 
					"  `use_time` int(11) default NULL COMMENT '用时[单位ms]',\r\n" + 
					"  `res_result` longtext COMMENT '响应结果',\r\n" + 
					"  `res_size` float default NULL COMMENT '响应数据大小[单位kb]',\r\n" + 
					"  `remark` text COMMENT '备注',\r\n" + 
					"  `create_time` datetime NOT NULL COMMENT '创建时间',\r\n" + 
					"  PRIMARY KEY  (`id`)\r\n" + 
					") ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='项目优化记录表';";
			batchExec(sql, baseDao);
			LOGGER.info("|===================================================");
		}
	}
	private static void createPrjOptimize(BaseDao baseDao) {
		try {
			baseDao.queryForLong("select count(*) from prj_optimize limit 1");
		} catch (Exception e) {
			LOGGER.info("|===================================================");
			LOGGER.error("|========== 不存在表[prj_optimize]: " + e.getMessage());
			String sql = "CREATE TABLE `prj_optimize` (\r\n" + 
					"  `id` int(11) NOT NULL auto_increment COMMENT '编码',\r\n" + 
					"  `prj_id` int(11) NOT NULL COMMENT '项目编号',\r\n" + 
					"  `url` varchar(200) NOT NULL COMMENT '接口地址',\r\n" + 
					"  `warn_time` int(11) NOT NULL COMMENT '预警时间[单位ms]',\r\n" + 
					"  `create_time` datetime NOT NULL COMMENT '创建时间',\r\n" + 
					"  PRIMARY KEY  (`id`)\r\n" + 
					") ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='项目优化规则表';";
			batchExec(sql, baseDao);
			LOGGER.info("|===================================================");
		}
	}
	private static void createPrjMonitor(BaseDao baseDao) {
		try {
			baseDao.queryForLong("select count(*) from prj_monitor limit 1");
		} catch (Exception e) {
			LOGGER.info("|===================================================");
			LOGGER.error("|========== 不存在表[prj_monitor]: " + e.getMessage());
			String sql = "CREATE TABLE `prj_monitor` (\r\n" + 
					"  `prjm_id` int(11) NOT NULL auto_increment COMMENT '编号',\r\n" + 
					"  `prj_id` int(11) NOT NULL COMMENT '项目编号',\r\n" + 
					"  `type` int(11) NOT NULL COMMENT '监控类型[10服务、20数据库、30缓存、40其它]',\r\n" + 
					"  `remark` varchar(100) NOT NULL COMMENT '描叙',\r\n" + 
					"  `monitor_is` int(11) NOT NULL COMMENT '是否检测',\r\n" + 
					"  `monitor_succ_str` varchar(100) default NULL COMMENT '检测成功标识',\r\n" + 
					"  `monitor_status` int(11) default NULL COMMENT '检测状态[10正常、20异常]',\r\n" + 
					"  `monitor_url` varchar(150) default NULL COMMENT '检测地址',\r\n" + 
					"  `monitor_time` datetime default NULL COMMENT '检测时间',\r\n" + 
					"  `monitor_fail_num` int(11) default NULL COMMENT '检测失败次数',\r\n" + 
					"  `monitor_fail_num_remind` int(11) default NULL COMMENT '检测失败最大次数提醒[0代表不提醒]',\r\n" + 
					"  `monitor_fail_email` varchar(50) default NULL COMMENT '检测失败接收邮箱',\r\n" + 
					"  `monitor_fail_send_time` datetime default NULL COMMENT '检测失败发送信息时间',\r\n" + 
					"  `monitor_fail_send_interval` int(11) default NULL COMMENT '检测失败发送信息间隔[单位：分钟]',\r\n" + 
					"  PRIMARY KEY  (`prjm_id`)\r\n" + 
					") ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='项目监控表';";
			batchExec(sql, baseDao);
			LOGGER.info("|===================================================");
		}
	}
	private static void createPrjInfo(BaseDao baseDao) {
		try {
			baseDao.queryForLong("select count(*) from prj_info limit 1");
		} catch (Exception e) {
			LOGGER.info("|===================================================");
			LOGGER.error("|========== 不存在表[prj_info]: " + e.getMessage());
			String sql = "CREATE TABLE `prj_info` (\r\n" + 
					"  `prj_id` int(11) NOT NULL auto_increment COMMENT '编号',\r\n" + 
					"  `code` varchar(50) NOT NULL COMMENT '项目编码',\r\n" + 
					"  `name` varchar(100) NOT NULL COMMENT '名称',\r\n" + 
					"  `remark` varchar(200) default NULL COMMENT '描叙',\r\n" + 
					"  `create_time` datetime NOT NULL COMMENT '添加时间',\r\n" + 
					"  `user_id` int(11) NOT NULL COMMENT '添加人',\r\n" + 
					"  `release_version` varchar(50) default NULL COMMENT '发布的版本号',\r\n" + 
					"  `release_time` datetime default NULL COMMENT '发布的版本时间',\r\n" + 
					"  `status` int(11) NOT NULL COMMENT '状态[10正常、20停用]',\r\n" + 
					"  `container` int(11) NOT NULL COMMENT '容器类型[10tomcat、50自定义服务、100其它]',\r\n" + 
					"  `shell_script` text COMMENT 'shell脚本',\r\n" + 
					"  `monitor_status` int(11) NOT NULL default '0' COMMENT '监控状态是否正常',\r\n" + 
					"  `monitor_msg` varchar(200) default NULL COMMENT '监控消息',\r\n" + 
					"  `stop_script` varchar(256) default NULL COMMENT '停止服务',\r\n" + 
					"  `restart_script` varchar(256) default NULL COMMENT '重启服务',\r\n" + 
					"  `tag` varchar(256) default NULL COMMENT '标签',\r\n" + 
					"  `root_dir` varchar(256) default NULL COMMENT '根目录',\r\n" + 
					"  PRIMARY KEY  (`prj_id`),\r\n" + 
					"  UNIQUE KEY `UQ_CODE` (`code`)\r\n" + 
					") ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='项目表';";
			batchExec(sql, baseDao);
			LOGGER.info("|===================================================");
		}
	}
	private static void createPrjDs(BaseDao baseDao) {
		try {
			baseDao.queryForLong("select count(*) from prj_ds limit 1");
		} catch (Exception e) {
			LOGGER.info("|===================================================");
			LOGGER.error("|========== 不存在表[prj_ds]: " + e.getMessage());
			String sql = "CREATE TABLE `prj_ds` (\r\n" + 
					"  `code` varchar(32) NOT NULL COMMENT '数据源编码',\r\n" + 
					"  `prj_id` int(11) NOT NULL COMMENT '项目编号',\r\n" + 
					"  `type` varchar(30) NOT NULL COMMENT '数据库类型[mysql/oracle]',\r\n" + 
					"  `driver_class` varchar(100) NOT NULL COMMENT '驱动类',\r\n" + 
					"  `url` varchar(100) NOT NULL COMMENT 'jdbc的url',\r\n" + 
					"  `username` varchar(50) NOT NULL COMMENT '用户名',\r\n" + 
					"  `password` varchar(50) NOT NULL COMMENT '密码',\r\n" + 
					"  `initial_size` int(11) NOT NULL COMMENT '初始连接数',\r\n" + 
					"  `max_idle` int(11) NOT NULL COMMENT '最大连接数',\r\n" + 
					"  `min_idle` int(11) NOT NULL COMMENT '最小连接数',\r\n" + 
					"  `test_sql` varchar(200) NOT NULL COMMENT '测试的sql语句',\r\n" + 
					"  `user_id` int(11) NOT NULL COMMENT '添加人',\r\n" + 
					"  `create_time` datetime NOT NULL COMMENT '添加时间',\r\n" + 
					"  PRIMARY KEY  (`code`,`prj_id`)\r\n" + 
					") ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='项目数据源表';";
			batchExec(sql, baseDao);
			LOGGER.info("|===================================================");
		}
	}
	private static void createPrjClient(BaseDao baseDao) {
		try {
			baseDao.queryForLong("select count(*) from prj_client limit 1");
		} catch (Exception e) {
			LOGGER.info("|===================================================");
			LOGGER.error("|========== 不存在表[prj_client]: " + e.getMessage());
			String sql = "CREATE TABLE `prj_client` (\r\n" + 
					"  `prj_id` int(11) NOT NULL COMMENT '项目编号',\r\n" + 
					"  `client_id` varchar(32) NOT NULL COMMENT '客户端编号',\r\n" + 
					"  `version` varchar(50) NOT NULL COMMENT '版本编号',\r\n" + 
					"  `status` int(11) NOT NULL COMMENT '状态[10待发布、20发布中、30发布失败、40发布成功]',\r\n" + 
					"  `status_msg` varchar(200) default NULL COMMENT '状态消息',\r\n" + 
					"  `release_time` datetime default NULL COMMENT '发布时间',\r\n" + 
					"  `shell_script` text COMMENT '客户端执行的Shell命令',\r\n" + 
					"  `log_path` varchar(150) default NULL COMMENT '日志路径',\r\n" + 
					"  `stop_script` varchar(256) default NULL COMMENT '停止服务',\r\n" + 
					"  `restart_script` varchar(256) default NULL COMMENT '重启服务',\r\n" + 
					"  PRIMARY KEY  (`prj_id`,`client_id`,`version`)\r\n" + 
					") ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='项目客户端表';";
			batchExec(sql, baseDao);
			LOGGER.info("|===================================================");
		}
	}
	private static void createPrjApi(BaseDao baseDao) {
		try {
			baseDao.queryForLong("select count(*) from prj_api limit 1");
		} catch (Exception e) {
			LOGGER.info("|===================================================");
			LOGGER.error("|========== 不存在表[prj_api]: " + e.getMessage());
			String sql = "CREATE TABLE `prj_api` (\r\n" + 
					"  `prj_id` int(11) NOT NULL COMMENT '项目编号',\r\n" + 
					"  `path` varchar(255) NOT NULL COMMENT '路径',\r\n" + 
					"  `name` varchar(200) default NULL COMMENT '名称',\r\n" + 
					"  `method` varchar(500) NOT NULL COMMENT '方法详情',\r\n" + 
					"  `params` text COMMENT '参数',\r\n" + 
					"  `response` text COMMENT '结果',\r\n" + 
					"  `is_use` int(11) NOT NULL COMMENT '是否使用',\r\n" + 
					"  `create_time` datetime NOT NULL COMMENT '新增时间',\r\n" + 
					"  `update_time` datetime NOT NULL COMMENT '更新时间',\r\n" + 
					"  PRIMARY KEY  (`prj_id`,`path`)\r\n" + 
					") ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='项目的API表';";
			batchExec(sql, baseDao);
			LOGGER.info("|===================================================");
		}
	}
	private static void createMsSecretApi(BaseDao baseDao) {
		try {
			baseDao.queryForLong("select count(*) from ms_secret_api limit 1");
		} catch (Exception e) {
			LOGGER.info("|===================================================");
			LOGGER.error("|========== 不存在表[ms_secret_api]: " + e.getMessage());
			String sql = "CREATE TABLE `ms_secret_api` (\r\n" + 
					"  `cli_id` varchar(32) NOT NULL COMMENT '客户端编号',\r\n" + 
					"  `prj_id` int(11) NOT NULL COMMENT '项目编号',\r\n" + 
					"  `prj_code` varchar(50) NOT NULL COMMENT '项目编码',\r\n" + 
					"  `url` varchar(150) NOT NULL COMMENT 'API地址',\r\n" + 
					"  `create_time` datetime NOT NULL COMMENT '创建时间',\r\n" + 
					"  PRIMARY KEY  (`cli_id`,`prj_id`,`url`)\r\n" + 
					") ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='密钥API权限表';";
			batchExec(sql, baseDao);
			LOGGER.info("|===================================================");
		}
	}
	private static void createMsSecret(BaseDao baseDao) {
		try {
			baseDao.queryForLong("select count(*) from ms_secret limit 1");
		} catch (Exception e) {
			LOGGER.info("|===================================================");
			LOGGER.error("|========== 不存在表[ms_secret]: " + e.getMessage());
			String sql = "CREATE TABLE `ms_secret` (\r\n" + 
					"  `cli_id` varchar(32) NOT NULL default '' COMMENT '客户端编号',\r\n" + 
					"  `name` varchar(100) NOT NULL COMMENT '名称',\r\n" + 
					"  `remark` varchar(100) default NULL COMMENT '备注',\r\n" + 
					"  `token` varchar(100) NOT NULL COMMENT '密钥',\r\n" + 
					"  `domain` varchar(200) default NULL COMMENT '主路径',\r\n" + 
					"  `is_use` int(11) NOT NULL COMMENT '是否使用',\r\n" + 
					"  `create_time` datetime NOT NULL COMMENT '创建时间',\r\n" + 
					"  `req_max_hour` bigint(20) NOT NULL default '0' COMMENT '每小时最大请求[0代表不限制]',\r\n" + 
					"  `req_max_second` bigint(20) NOT NULL default '0' COMMENT '每秒最大请求数[0代表不限制]',\r\n" + 
					"  PRIMARY KEY  (`cli_id`)\r\n" + 
					") ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='应用密钥表';";
			sql += "insert into `ms_secret` (`cli_id`, `name`, `remark`, `token`, `domain`, `is_use`, `create_time`) values('143756892','config','配置系统的密钥','4307a39dfc7ecb783d6682f44s3911e2','','1','2017-06-11 12:00:40');\r\n" + 
					"insert into `ms_secret` (`cli_id`, `name`, `remark`, `token`, `domain`, `is_use`, `create_time`) values('145756897','biz','biz项目的密钥','6e09a39dfc7edb7w3d66f2f44s3913e2','','1','2017-06-11 12:05:45');";
			batchExec(sql, baseDao);
			LOGGER.info("|===================================================");
		}
	}
	private static void createMsConfig(BaseDao baseDao) {
		try {
			baseDao.queryForLong("select count(*) from ms_config limit 1");
		} catch (Exception e) {
			LOGGER.info("|===================================================");
			LOGGER.error("|========== 不存在表[ms_config]: " + e.getMessage());
			String sql = "CREATE TABLE `ms_config` (\r\n" + 
					"  `config_id` int(11) NOT NULL auto_increment COMMENT '编号',\r\n" + 
					"  `name` varchar(100) NOT NULL COMMENT '文件名称',\r\n" + 
					"  `remark` varchar(250) default NULL COMMENT '备注',\r\n" + 
					"  `content` text default NULL COMMENT '配置文件内容',\r\n" + 
					"  `is_use` int(11) NOT NULL COMMENT '是否使用',\r\n" + 
					"  `create_time` datetime NOT NULL COMMENT '创建日期',\r\n" + 
					"  `user_id` int(11) NOT NULL COMMENT '添加人',\r\n" + 
					"  `prj_id` int(11) NOT NULL default '0' COMMENT '项目编号',\r\n" + 
					"  PRIMARY KEY  (`config_id`)\r\n" + 
					") ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='配置文件表';";
			//sql += "insert  into `ms_config`(`config_id`,`name`,`remark`,`content`,`is_use`,`create_time`,`user_id`,`prj_id`) values (1,'ms-cloud-monitor.properties','微服务的Monitor配置文件','spring.application.name=ms-cloud-monitor\\nserver.port=7250\\n\\n#实例名称显示ip\\neureka.instance.preferIpAddress=true\\n#只应该在application.yml中设置。如果设置在bootstrap.yml中将会导致一些不良的副作用，例如在Eureka中注册的应用名称是UNKNOWN等。\\n#eureka.client.healthcheck.enabled=true\\neureka.client.serviceUrl.defaultZone=http://msRc:7200/eureka/\\n\\nspring.jackson.time-zone=GMT+8\\nspring.jackson.date-format=yyyy-MM-dd HH:mm:ss\\n\\n#这个是关闭thymeleaf缓存\\nspring.thymeleaf.cache=false\\n#关闭thymeleaf模板\\nspring.thymeleaf.enabled=false\\n\\n#关闭freemarker缓存\\n#spring.freemarker.cache=false\\n#spring.freemarker.charset=UTF-8\\n#spring.freemarker.template-loader-path=classpath:/template/code/\\n\\nspring.view.prefix=/WEB-INF/view/\\nspring.view.suffix=.jsp\\n\\n\\nserver.servlet.context-path=/\\n\\n\\n#spring.cloud.config.profile=dev\\n#spring.cloud.config.label=master\\n#spring.cloud.config.uri=http://localhost:7001/\\n\\n#tomcat最大线程数\\nserver.tomcat.max-threads=30\\n\\n#限制上传文件的大小\\nmultipart.maxFileSize=200MB\\nmultipart.maxRequestSize=200MB\\n\\n#session过期时间[24小时]\\nserver.servlet.session.timeout=86400\\n\\n#项目名称\\nproject.monitor.name=Monitor\\n\\n#tomcat的临时目录\\nserver.tomcat.basedir=/app/appsoft/ms-cloud-monitor-1.0.0/tmp\\n#生成源码的模板存放路径\\ncode.template.path=D:\\\\\\\\data\\\\\\\\monitor\\\\\\\\template\\n#生成的源码存放路径\\ncode.source.path=D:\\\\\\\\data\\\\\\\\monitor\\\\\\\\source\\n\\n#数据库连接信息\\njdbc1.driverClassName=com.mysql.jdbc.Driver\\njdbc1.url=jdbc:mysql://127.0.0.1:3306/monitor?useUnicode=true&characterEncoding=UTF-8\\njdbc1.username=root\\njdbc1.password=root\\n#jdbc1.initialSize=10\\n#jdbc1.maxActive=50\\n#jdbc1.maxIdle=30\\n#jdbc1.minIdle=10\\n\\n#zipkin日志数据库连接信息\\njdbc2.driverClassName=com.mysql.jdbc.Driver\\njdbc2.url=jdbc:mysql://127.0.0.1:3306/log?useUnicode=true&characterEncoding=UTF-8\\njdbc2.username=root\\njdbc2.password=root\\n\\n#redis 配置 hosts多个用;分隔\\nredis.hosts=127.0.0.1:6379;\\nredis.password=\\nredis.maxIdle=500\\nredis.maxTotal=1000\\nredis.maxWaitMillis=100000\\nredis.keyPrefix=msm-\\n\\n#请求其它服务的唯一ID\\nproject.client.id=145756897\\n#请求其它服务的密钥\\nproject.sercret=6e09a39dfc7edb7w3d66f2f44s3913e2\\n#定时任务的服务ID\\nservice.id.task=ms-cloud-task\\n#配置中心的服务ID\\nservice.id.config=ms-cloud-config\\n\\n#log的日志查看host\\nspring.zipkin.ui.host=http://127.0.0.1:7400/zipkin\\n#client.log.server.host=http://msLog:7400\\n#client.log.server.serviceId=ms-cloud-log\\n',1,'2019-03-23 15:44:14',1,3),"
			//		+ "(2,'ms-cloud-task.properties','定时任务的配置文件','spring.application.name=ms-cloud-task\\nserver.port=7280\\n\\n#实例名称显示ip\\neureka.instance.preferIpAddress=true\\n#只应该在application.yml中设置。如果设置在bootstrap.yml中将会导致一些不良的副作用，例如在Eureka中注册的应用名称是UNKNOWN等。\\n#eureka.client.healthcheck.enabled=true\\neureka.client.serviceUrl.defaultZone=http://msRc:7200/eureka/\\n\\n#spring.cloud.config.profile=dev\\n#spring.cloud.config.label=master\\n#spring.cloud.config.uri=http://localhost:7001/\\n\\n#暴露/actuator/refresh接入点\\nmanagement.endpoints.web.exposure.include=refresh\\n\\n#这个是关闭thymeleaf缓存\\nspring.thymeleaf.cache=false\\n#关闭thymeleaf模板\\nspring.thymeleaf.enabled=false\\n\\nspring.jackson.time-zone=GMT+8\\nspring.jackson.date-format=yyyy-MM-dd HH:mm:ss\\n\\n\\njdbc1.driverClassName=com.mysql.jdbc.Driver\\njdbc1.url=jdbc:mysql://127.0.0.1:3306/task?useUnicode=true&characterEncoding=UTF-8\\njdbc1.username=root\\njdbc1.password=root\\n#jdbc1.initialSize=10\\n#jdbc1.maxActive=50\\n#jdbc1.maxIdle=30\\n#jdbc1.minIdle=10\\n\\n#项目的信息\\nproject.client.id=145756897\\nproject.sercret=6e09a39dfc7edb7w3d66f2f44s3913e2\\n#监控的服务编码\\nservice.id.monitor=ms-cloud-monitor\\n\\n#任务的执行线程数,不设置默认为100\\nproject.task.thread.num=100',1,'2019-03-23 21:24:56',1,0),"
			//		+ "(3,'ms-cloud-zuul.properties','网关的配置文件','spring.application.name=ms-cloud-zuul\\nserver.port=7300\\n\\n#实例名称显示ip\\neureka.instance.preferIpAddress=true\\n#只应该在application.yml中设置。如果设置在bootstrap.yml中将会导致一些不良的副作用，例如在Eureka中注册的应用名称是UNKNOWN等。\\n#eureka.client.healthcheck.enabled=true\\neureka.client.serviceUrl.defaultZone=http://msRc:7200/eureka/\\n\\n#设置超时时间\\nhystrix.command.default.execution.timeout.enabled=true\\nhystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=60000\\nzuul.max.host.connections=5000\\nzuul.host.socket-timeout-millis=60000\\nzuul.host.connect-timeout-millis=60000\\nribbon.ConnectTimeout=8000\\nribbon.ReadTimeout=60000\\n\\n#暴露/actuator/refresh接入点\\nmanagement.endpoints.web.exposure.include=refresh\\n\\n#项目的信息\\nproject.client.id=145756897\\nproject.sercret=6e09a39dfc7edb7w3d66f2f44s3913e2\\n#监控的服务编码\\nservice.id.monitor=ms-cloud-monitor\\n\\n#redis\\nredis.hosts=127.0.0.1:6379;\\nredis.password=\\nredis.maxIdle=500\\nredis.maxTotal=1000\\nredis.maxWaitMillis=100000\\nredis.keyPrefix=mszuul-\\n\\n\\n#routes to url\\nzuul.routes.biz-base.path=/biz-base/**\\nzuul.routes.biz-base.serviceId=biz-base\\n#设置是否显示微服务的根目录\\nzuul.routes.biz-base.stripPrefix=true\\nzuul.routes.biz-base.sensitiveHeaders=*\\n\\nzuul.routes.biz-ucenter.path=/biz-ucenter/**\\nzuul.routes.biz-ucenter.serviceId=biz-ucenter\\n#设置是否显示微服务的根目录\\nzuul.routes.biz-ucenter.stripPrefix=true\\nzuul.routes.biz-ucenter.sensitiveHeaders=*\\n\\n#zuul.routes.thymeleaf.path=/thymeleaf/**\\n#zuul.routes.thymeleaf.serviceId=biz-service-thymeleaf\\n\\n#zuul.routes.eureka.path=/eureka/**\\n#zuul.routes.eureka.serviceId=ms-cloud-eureka\\n\\n#zuul.routes.monitor.path=/monitor/**\\n#zuul.routes.monitor.serviceId=ms-cloud-monitor\\n\\n\\n#这里的配置表示，访问/baidu/** 直接重定向到http://www.baidu.com\\n#zuul.routes.baidu.path=/baidu/**\\n#zuul.routes.baidu.url=http://www.baidu.com\\n\\n#url重写配置\\n#这里的配置，相当于访问/index/** 会直接渲染/home的请求内容(和直接请求/home效果一样), url地址不变\\n#zuul.routes.index.path=/index/**\\n#zuul.routes.index.url=forward:/home\\n',1,'2019-03-31 15:07:53',1,0),"
			//		+ "(4,'biz-ucenter.properties','用户中心的配置文件','spring.application.name=biz-ucenter\\nserver.port=8110\\n\\n#实例名称显示ip\\neureka.instance.preferIpAddress=true\\n#只应该在application.yml中设置。如果设置在bootstrap.yml中将会导致一些不良的副作用，例如在Eureka中注册的应用名称是UNKNOWN等。\\n#eureka.client.healthcheck.enabled=true\\n#注册中心地址\\neureka.client.serviceUrl.defaultZone=http://msRc:7200/eureka/\\n\\nspring.jackson.time-zone=GMT+8\\nspring.jackson.date-format=yyyy-MM-dd HH:mm:ss\\n\\n\\n#暴露/actuator/refresh接入点\\nmanagement.endpoints.web.exposure.include=refresh\\n\\n#项目的信息\\nproject.client.id=145756897\\nproject.sercret=6e09a39dfc7edb7w3d66f2f44s3913e2\\n#监控的服务编码\\nservice.id.monitor=ms-cloud-monitor\\n#基础服务的编码\\nservice.id.biz-base=biz-base\\n\\n\\n#redis 配置 hosts多个用;分隔\\n#redis.hosts=redis://10.201.224.175:6379/3;\\n#redis.password=\\n#redis.maxIdle=500\\n#redis.maxTotal=1000\\n#redis.maxWaitMillis=100000\\n#redis.keyPrefix=bsa-\\n\\n#数据源\\njdbc1.driverClassName=com.mysql.jdbc.Driver\\njdbc1.url=jdbc:mysql://127.0.0.1:3306/biz-ucenter?useUnicode=true&characterEncoding=UTF-8\\njdbc1.username=root\\njdbc1.password=root\\n\\n#文件上传的目录\\nproject.file.path=D:\\\\\\\\data\\\\\\\\ucenter\\n#上传文件临时目录\\nspring.http.multipart.location=${user.dir}/upload_tmp\\n\\n\\n#采样率，默认0.1即10%,如需测试时每次都看到trace则修改为1.0，但对性能有影响，注意上线时修改为合理值\\nspring.sleuth.sampler.probability=1.0\\n#zipkin的请求路径\\nspring.zipkin.base-url=http://msLog:7400\\n#zipkin发送类型RABBIT/KAFKA/WEB\\nspring.zipkin.sender.type=WEB',1,'2019-04-04 16:57:28',1,0),(6,'biz-base.properties','','spring.application.name=biz-base\\nserver.port=8100\\n\\n#实例名称显示ip\\neureka.instance.preferIpAddress=true\\n#只应该在application.yml中设置。如果设置在bootstrap.yml中将会导致一些不良的副作用，例如在Eureka中注册的应用名称是UNKNOWN等。\\n#eureka.client.healthcheck.enabled=true\\n#注册中心地址\\neureka.client.serviceUrl.defaultZone=http://msRc:7200/eureka/\\n\\nspring.jackson.time-zone=GMT+8\\nspring.jackson.date-format=yyyy-MM-dd HH:mm:ss\\n\\n#这里是限制的文件大小\\nmultipart.maxFileSize=10MB\\nmultipart.maxRequestSize=10MB\\n#上传文件临时目录\\nspring.http.multipart.location=${user.dir}/upload_tmp\\n\\n#采样率，默认0.1即10%,如需测试时每次都看到trace则修改为1.0，但对性能有影响，注意上线时修改为合理值\\n#spring.zipkin.sleuth.sampler.percentage=1.0\\n#spring.zipkin.base-url=http://msLog:7400\\n\\n#暴露/actuator/refresh接入点\\nmanagement.endpoints.web.exposure.include=refresh\\n\\n#项目的信息\\nproject.client.id=145756897\\nproject.sercret=6e09a39dfc7edb7w3d66f2f44s3913e2\\n#监控的服务编码\\nservice.id.monitor=ms-cloud-monitor\\n\\n\\n#redis 配置 hosts多个用;分隔\\n#redis.hosts=redis://10.201.224.175:6379/3;\\n#redis.password=\\n#redis.maxIdle=500\\n#redis.maxTotal=1000\\n#redis.maxWaitMillis=100000\\n#redis.keyPrefix=bsa-\\n\\n#数据库连接\\njdbc1.driverClassName=com.mysql.jdbc.Driver\\njdbc1.url=jdbc:mysql://127.0.0.1:3306/biz-base?useUnicode=true&characterEncoding=UTF-8\\njdbc1.username=root\\njdbc1.password=root\\n\\n#文件上传的目录\\nproject.file.path=D:\\\\\\\\data\\\\\\\\file\\n#search索引的目录[服务如果集群,需要将索引的目录做nfs共享或单独抽离服务]\\nsearch.index.path=D://data//indexfile\\n\\n#采样率，默认0.1即10%,如需测试时每次都看到trace则修改为1.0，但对性能有影响，注意上线时修改为合理值\\nspring.sleuth.sampler.probability=1.0\\n#zipkin的请求路径\\nspring.zipkin.base-url=http://msLog:7400\\n#zipkin发送类型RABBIT/KAFKA/WEB\\nspring.zipkin.sender.type=WEB\\n\\n#记录业务日志[0否、1是]\\nsave.log.open=1\\n',1,'2019-08-05 14:39:28',1,11);";
			batchExec(sql, baseDao);
			LOGGER.info("|===================================================");
		}
	}
	private static void createCodeTemplate(BaseDao baseDao) {
		try {
			baseDao.queryForLong("select count(*) from code_template limit 1");
		} catch (Exception e) {
			LOGGER.info("|===================================================");
			LOGGER.error("|========== 不存在表[code_template]: " + e.getMessage());
			String sql = "CREATE TABLE `code_template` (\r\n" + 
					"  `code` varchar(50) NOT NULL COMMENT '源码编号',\r\n" + 
					"  `type` int(11) NOT NULL COMMENT '类型[10java、20jsp、30其它文件]',\r\n" + 
					"  `name` varchar(100) NOT NULL COMMENT '名称',\r\n" + 
					"  `remark` varchar(200) default NULL COMMENT '描叙',\r\n" + 
					"  `package_name` varchar(30) NOT NULL COMMENT '包名',\r\n" + 
					"  `content` text NOT NULL COMMENT '模板内容',\r\n" + 
					"  `path` varchar(200) NOT NULL COMMENT '模板路劲',\r\n" + 
					"  `suffix` varchar(50) default NULL COMMENT '文件后缀',\r\n" + 
					"  PRIMARY KEY  (`code`,`name`)\r\n" + 
					") ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='项目模板表';";
			batchExec(sql, baseDao);
			LOGGER.info("|===================================================");
		}
	}
	private static void createCodePrj(BaseDao baseDao) {
		try {
			baseDao.queryForLong("select count(*) from code_prj limit 1");
		} catch (Exception e) {
			LOGGER.info("|===================================================");
			LOGGER.error("|========== 不存在表[code_prj]: " + e.getMessage());
			String sql = "CREATE TABLE `code_prj` (\r\n" + 
					"  `code` varchar(50) NOT NULL COMMENT '编码',\r\n" + 
					"  `prj_id` int(11) NOT NULL COMMENT '项目编号',\r\n" + 
					"  `name` varchar(150) NOT NULL COMMENT '名称',\r\n" + 
					"  `create_time` datetime NOT NULL COMMENT '创建时间',\r\n" + 
					"  `user_id` int(11) NOT NULL COMMENT '创建人',\r\n" + 
					"  PRIMARY KEY  (`code`)\r\n" + 
					") ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='项目源码表';";
			batchExec(sql, baseDao);
			LOGGER.info("|===================================================");
		}
	}
	private static void createCodeCreate(BaseDao baseDao) {
		try {
			baseDao.queryForLong("select count(*) from code_create limit 1");
		} catch (Exception e) {
			LOGGER.info("|===================================================");
			LOGGER.error("|========== 不存在表[code_create]: " + e.getMessage());
			String sql = "CREATE TABLE `code_create` (\r\n" + 
					"  `id` int(11) NOT NULL auto_increment COMMENT '编号',\r\n" + 
					"  `code` varchar(50) NOT NULL COMMENT '源码编号',\r\n" + 
					"  `package_path` varchar(200) NOT NULL COMMENT '功能包路径',\r\n" + 
					"  `status` int(11) NOT NULL COMMENT '状态[10待生成、20生成中、30生成失败、40生成成功]',\r\n" + 
					"  `download` varchar(200) default NULL COMMENT '下载地址',\r\n" + 
					"  `finish_time` datetime default NULL COMMENT '生成完成时间',\r\n" + 
					"  `ds_code` varchar(100) NOT NULL COMMENT '数据源编号',\r\n" + 
					"  `db_name` varchar(100) NOT NULL COMMENT '数据库名',\r\n" + 
					"  `tables` varchar(200) NOT NULL COMMENT '生成的表集合[多个,分隔]',\r\n" + 
					"  `create_time` datetime NOT NULL COMMENT '创建时间',\r\n" + 
					"  `user_id` int(11) NOT NULL COMMENT '创建人',\r\n" + 
					"  PRIMARY KEY  (`id`)\r\n" + 
					") ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='生成源码表';";
			batchExec(sql, baseDao);
			LOGGER.info("|===================================================");
		}
	}

	private static void createCliInfo(BaseDao baseDao) {
		try {
			baseDao.queryForLong("select count(*) from cli_info limit 1");
		} catch (Exception e) {
			LOGGER.info("|===================================================");
			LOGGER.error("|========== 不存在表[cli_info]: " + e.getMessage());
			String sql = "CREATE TABLE `cli_info` (\r\n" + 
					"  `client_id` varchar(32) NOT NULL COMMENT '客户端编号',\r\n" + 
					"  `name` varchar(50) NOT NULL COMMENT '名称',\r\n" + 
					"  `remark` varchar(200) default NULL COMMENT '描叙',\r\n" + 
					"  `ip` varchar(30) NOT NULL COMMENT 'ip地址',\r\n" + 
					"  `port` int(11) NOT NULL COMMENT '端口',\r\n" + 
					"  `token` varchar(100) NOT NULL COMMENT '密钥',\r\n" + 
					"  `create_time` datetime NOT NULL COMMENT '添加时间',\r\n" + 
					"  `user_id` int(11) NOT NULL COMMENT '添加人',\r\n" + 
					"  `status` int(11) NOT NULL COMMENT '状态[10正常、20停用]',\r\n" + 
					"  `activity_status` int(11) default NULL COMMENT '活动状态[10正常、20心跳异常]',\r\n" + 
					"  `activity_time` datetime default NULL COMMENT '上次活动时间',\r\n" + 
					"  PRIMARY KEY  (`client_id`)\r\n" + 
					") ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='客户端表';";
			batchExec(sql, baseDao);
			/*
			sql = "alter table sys_user comment '用户表'";
			baseDao.updateSql(sql);
			sql = "create unique index unique_username on sys_user\r\n" + 
					"(\r\n" + 
					"   username\r\n" + 
					")";
			baseDao.updateSql(sql);
			String pwd = FrameMd5Util.getInstance().encodePassword("123456", "1");
			sql = "INSERT INTO `sys_user`(`id`,`username`,`password`,`nickname`,`addtime`,`adduser`,`status`)\r\n" + 
					" VALUES (1,'admin','" + pwd + "','管理员',now(),1,0)";
			baseDao.saveSql(sql);*/
			LOGGER.info("|===================================================");
		}
	}

	private static void batchExec(String sql, BaseDao baseDao) {
		List<String> sqls = FrameStringUtil.toArray(sql, ";");
		for (String s : sqls) {
			if (FrameStringUtil.isEmpty(s)) {
				continue;
			}
			baseDao.updateSql(s);
		}
	}
}
